package com.xiaoma.processor;

import com.xiaoma.domain.Login;
import com.xiaoma.observer.DDSendChannel;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;

/**
 * @description  
 * @author wangtianxiang
 * @date: 2021/11/24 16:26
 */
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {


    private String name;

    public MyBeanDefinitionRegistryPostProcessor(String name) {
        this.name = name;
    }

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        System.out.println("name" + name + "...bean的数量："+registry.getBeanDefinitionCount());
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(DDSendChannel.class).getBeanDefinition();
        registry.registerBeanDefinition("dDSendChannel", beanDefinition);

    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

        System.out.println("name" + name + "...bean的数量：" + beanFactory.getBeanDefinitionCount());
    }
}
